<template>
	<view class="content">
		<z-paging ref="paging" v-model="dataList" :default-page-size="row" @onRefresh="onRefresh" @query="getList"
			auto-show-system-loading auto-show-back-to-top>
			<view class="list-box" v-for="(item,index) in dataList" :key="index">
				<view class="title">
					{{index+1}}、{{item.createBy}}
				</view>
				<view class="item-box" v-if="item.grantDate">
					<view class="title">
						发放日期
					</view>
					<view class="text">
						{{item.grantDate}}
					</view>
				</view>
				<view class="item-box" v-if="item.companyName">
					<view class="title">
						发放公司
					</view>
					<view class="text">
						{{$tools.dictDispose(company,item.companyName)}}
					</view>
				</view>
				<view class="item-box" v-if="item.grantMoney">
					<view class="title">
						发放金额
					</view>
					<view class="text">
						{{item.grantMoney}}
					</view>
				</view>
				<view class="item-box" v-if="item.proName">
					<view class="title">
						发放记录
					</view>
					<view class="text">
						{{item.proName}}
					</view>
				</view>
				<view class="item-box" v-if="item.remark">
					<view class="title">
						备注
					</view>
					<view class="text">
						{{item.remark}}
					</view>
				</view>
				<view class="xian"></view>
				<view class="bnt-box">
					<view class="bnt-big-box">
						<view class="bnt" @click="deleteBnt(item)">
							删除
						</view>
					</view>
				</view>
			</view>
			<view style="height: 150rpx;">
			</view>
		</z-paging>
		<view class="bottom-box">
			<view class="bnt" @click="goto('/pagesA/applyAdmin/reimbursemenDetails/addRecord/index')">
				新增发放记录
			</view>
		</view>
	</view>
</template>

<script>
	import * as index from '@/api/index.js'
	export default {
		data() {
			return {
				row: 10,
				dataList: [],
				company: []
			}
		},
		onLoad(e) {
			this.id = e.id
			this.dictType()
		},
		methods: {
			reload() {
				console.log('重新加载');
				this.$nextTick(() => {
					this.$refs.paging.reload()
				})
			},
			goto(e,item) {
				uni.navigateTo({
					url:e + '?id=' + this.id
				})
			},
			// 数据字典
			dictType() {
				index.typesBatch({
					'company': 'company'
				}).then(res => {
					this.company = res.data.company
				})
			},
			// 删除工序
			deleteBnt(e) {
				uni.showModal({
					title: '提示',
					content: '确定删除工序吗？',
					success: (res) => {
						if (res.confirm) {
							index.goodsReimbursementDetailDelete(e).then(res => {
								setTimeout(res => {
									this.$refs.paging.reload()
								}, 100)
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			// 当页面滚动到底部事件被触发
			onReachBottom() {
				// 通知z-paging滚动到底部了，z-paging会进行相应的处理，例如加载更多数据
				this.$refs.paging.pageReachBottom();
			},
			// 下拉刷新被触发
			onRefresh() {
				// 告知z-paging下拉刷新结束，这样才可以开始下一次的下拉刷新
				setTimeout(() => {
					this.$tools.toast('刷新成功～')
				}, 500)
			},
			// @query所绑定的方法不要自己调用！！需要刷新列表数据时，只需要调用this.$refs.paging.reload()即可
			getList(pageNum, pageSize) {
				index.goodsReimbursementDetailList({
					pageNum,
					pageSize,
					reimburseId: this.id,
				}).then(res => {
					this.$refs.paging.complete(res.rows);
					console.log(res, '这是什么')
				})
			},
		}

	}
</script>

<style lang="scss">
	.content {
		padding: 20rpx 20rpx 20rpx 20rpx;

		.list-box {
			padding: 20rpx;
			background: #ffffff;
			border-radius: 8rpx;
			margin-bottom: 30rpx;

			.title {
				padding-top: 20rpx;
				padding-bottom: 20rpx;
				color: #333;
				font-size: 28rpx;
				font-weight: bold;
			}

			.item-box {
				padding-top: 7rpx;
				padding-bottom: 7rpx;
				padding-left: 10rpx;
				display: flex;
				align-items: center;
				border-top: 1px solid #EDEDED;

				.title {
					color: #999999;
					width: 180rpx;
				}

				.text {
					width: 420rpx;
				}
			}

			.xian {
				width: 662rpx;
				border-bottom: 1px solid #EAEAEA;
			}

			.bnt-box {
				padding-top: 20rpx;
				padding-bottom: 20rpx;

				.bnt-big-box {
					display: flex;
					justify-content: space-between;
					flex-wrap: wrap;

					.bnt {
						color: #4D8987;
						font-size: 24rpx;
						flex: 0 0 24%;
						height: 30px;
						display: flex;
						align-items: center;
						justify-content: center;
						border-radius: 10rpx;
						background: #F5F7FB;
						text-align: center;
						/* 边距懒得算，css函数代替 */
						margin-right: calc(4% / 3);
						margin-bottom: calc(4% / 3);

					}

					/* 去除每行尾的多余边距 */
					.bnt:nth-child(4n) {
						margin-right: 0;
					}

					/* 使最后一个元素的边距填满剩余空间 */
					.bnt:last-child {
						margin-right: auto;
					}
				}
			}
		}

		.bottom-box {
			position: fixed;
			bottom: 0;
			left: 0;
			width: 750rpx;
			padding: 30rpx;
			padding-bottom: 120rpx;
			height: 120rpx;
			background: #ffffff;
			display: flex;
			justify-content: center;

			.bnt {
				color: #ffffff;
				width: 306rpx;
				height: 88rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				border-radius: 10rpx;
				background: #4D8987;
			}
		}
	}
</style>